package com.jcl.recruit.elasticsearch.mapper;

import com.jcl.recruit.elasticsearch.resume.model.ResumeExternalMsg;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ClassName ResumeExternalMsgMapper

 * @Author yyliu
 * @Date 2018/10/15 14:01
 * @Version 1.0
 **/
public interface ResumeExternalMsgMapper {

    @Select({
            "select * from resume_external_msg where category = #{type}",
    })
    List<ResumeExternalMsg> findListByType(@Param("type") Integer type);

    @Select({
            "select * from resume_external_msg where resume_id = #{resumeId} and category = #{type}",
    })
    List<ResumeExternalMsg> findListByResumeId(@Param("resumeId") int resumeId, @Param("type") Integer type);


    @Select({
            "<script>",
            " select * from resume_external_msg where resume_id in ",
            "<foreach collection=\"resumeIds\" item=\"resumeId\" open=\"(\" close=\")\" separator=\",\"> " ,
            " #{resumeId}",
            "</foreach> ",
            " and category = #{type}",
            "</script>"
    })
    List<ResumeExternalMsg> findListByResumeIds(@Param("resumeIds") List<Integer> resumeIds,
                                                @Param("type") Integer type);

    @Insert({
            "insert into resume_external_msg ",
            "(resume_id,  context, external_id, category, source) ",
            "values ( ",
            "#{resumeId, jdbcType=INTEGER}, #{context, jdbcType=VARCHAR}, ",
            "#{externalId, jdbcType=VARCHAR}, #{category, jdbcType=INTEGER}, #{source, jdbcType=VARCHAR}",
            ")"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int add(ResumeExternalMsg resumeExternalMsg);
}
